package com.ms.dsq_english.utils;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;

public class VersionCodeUtils
{
    public static int getAppVersion(Context context)
    {
        int code = 0;

        try
        {
            code = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
        } catch (PackageManager.NameNotFoundException e)
        {
            e.printStackTrace();
        }

        return code;
    }

    public static String getAppVersionName(Context context)
    {
        String versionName="";

        try
        {
             versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        }
        catch (PackageManager.NameNotFoundException e)
        {
            e.printStackTrace();
        }

        return versionName;
    }

    public static String getDeviceId(Context context)
    {
        TelephonyManager manager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);

        //获取IMSI号
        @SuppressLint({"MissingPermission", "HardwareIds"})
        String imsi = manager.getSubscriberId();

        //获取IMEI号
        @SuppressLint({"MissingPermission", "HardwareIds"})
        String imei = manager.getDeviceId();

        return imei;
    }

    //获取软件包名,版本名，版本号
    public static String getAppInfo(Context context)
    {
        try
        {
            String pkName = context.getPackageName();
            int versionCode = context.getPackageManager().getPackageInfo(pkName, 0).versionCode;
            String versionName = context.getPackageManager().getPackageInfo(pkName, 0).versionName;

            return "包名:" + pkName +
                    "\n版本号:" + versionCode +
                    "\n版本名:" + versionName +
                    "\nAndroidId:" + getAndroidId(context);
        } catch (PackageManager.NameNotFoundException e)
        {
            e.printStackTrace();
        }

        return "";
    }

    @SuppressLint("HardwareIds")
    public static String getAndroidId(Context context)
    {
        return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    }

    public static String getPhoneInfo()
    {
        //手机品牌
        String brand = android.os.Build.BRAND;
        //手机型号
        String model = android.os.Build.MODEL;

        return "手机品牌：" + brand +
                " 手机型号：" + model;
    }

    public static String getSystemVersion()
    {
        //系统版本号
        String code = android.os.Build.VERSION.RELEASE;

        return "系统版本号：" + code;
    }
}
